package com.example.neusoft.yuejian_12.Activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.neusoft.yuejian_12.JavaBean.Contest;
import com.example.neusoft.yuejian_12.Listener.ContestDetailListener;
import com.example.neusoft.yuejian_12.Model.ContestModel;
import com.example.neusoft.yuejian_12.R;
import com.squareup.picasso.Picasso;

public class ContestDetailActivity extends AppCompatActivity implements ContestDetailListener,View.OnClickListener {
    private Contest info;
    private String id;
    private ImageView pic;
    private  ImageView back;
    private TextView tname,cintro,ctime,chit,cplace;
    private  String name,thumb,introduction,update_time,hits;
    String adress;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contestdetail);
        final Bundle bundle = getIntent().getExtras();
        id = bundle.getString("id");
        ContestModel model = new ContestModel();
        model.getdetail(id, this);
        initViews();
        back.setOnClickListener(this);
        cplace.setOnClickListener(this);

    }
    public void initViews() {
        tname = (TextView) findViewById(R.id.tname);
        pic = (ImageView) findViewById(R.id.tpic);
        back=(ImageView)findViewById(R.id.back);
        cintro=(TextView)findViewById(R.id.cintro);
        ctime=(TextView)findViewById(R.id.ctime);
        chit=(TextView)findViewById(R.id.chit);
        cplace=(TextView)findViewById(R.id.cplace);
    }

    @Override
    public void onResponse(Contest listBean) {
        info=listBean;
        adress=info.getUrl();
        name = info.getName();
        introduction=info.getIntroduction().replaceAll("</p>","").replaceAll("<p>","");
        update_time=info.getUpdate_time();
        thumb = info.getThumb();
        hits=info.getHits();

        cplace.setText(adress);
        tname.setText(name);
        cintro.setText(introduction);
        ctime.setText(update_time);
        chit.setText(hits);
        if (thumb != "") {
            Picasso.with(ContestDetailActivity.this)
                    .load("http://172.24.10.175/workout/Uploads/" + thumb)
                    .into(pic);
            pic.setScaleType(ImageView.ScaleType.FIT_XY);
        } else {
            pic.setImageResource(R.drawable.qya);
        }
    }

    @Override
    public void onFail(String msg) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){

            case R.id.back:
                finish();

            case R.id.cplace:
                Intent intent = new Intent();
                intent.setData(Uri.parse(adress));
                intent.setAction(Intent.ACTION_VIEW);
                startActivity(intent);
        }
    }
}
